package com.fram.controller.admin;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.sys.PageBean;
import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.apiversion.ApiVersion;
import com.fram.entity.HomeMenu;
import com.fram.service.admin.HomeMenuAdminService;

@RestController
@RequestMapping("/admin/{version}/auth/menu")
public class HomeMenuAdminController {
	
	private static Logger LOG = LoggerFactory.getLogger(HomeMenuAdminController.class);
	
	@Autowired
	private HomeMenuAdminService homeMenuAdminService;
	
	@ApiVersion(1.0)
	@RequestMapping(value = "/list")
	private ResponseMsg list(@RequestBody PageBean<HomeMenu> request) {
		ResponseMsg msg=ResponseMsg.returnBeanBuild();
		try {
			msg.setData(homeMenuAdminService.list(request));
		} catch (ProException e) {
			LOG.error("-后台首页列表出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--后台首页列表异常-->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	@ApiVersion(1.0)
	@RequestMapping(value = "/add")
	private ResponseMsg add(@RequestBody HomeMenu request) {
		ResponseMsg msg=ResponseMsg.returnBeanBuild();
		try {
			homeMenuAdminService.add(request);
		} catch (ProException e) {
			LOG.error("-首页列表增加出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--首页列表增加异常-->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	@ApiVersion(1.0)
	@RequestMapping(value = "/update")
	private ResponseMsg update(@RequestBody HomeMenu request) {
		ResponseMsg msg=ResponseMsg.returnBeanBuild();
		try {
			homeMenuAdminService.update(request);
		} catch (ProException e) {
			LOG.error("-首页列表修改出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--首页列表修改异常-->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	@ApiVersion(1.0)
	@RequestMapping(value = "/details")
	private ResponseMsg details(Long id) {
		ResponseMsg msg=ResponseMsg.returnBeanBuild();
		try {
			msg.setData(homeMenuAdminService.details(id));
		} catch (ProException e) {
			LOG.error("-首页列表详情出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--首页列表详情异常-->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
